import requests
newsurl='http://news.sina.com.cn/china/'
res=requests.get(newsurl)
res.encoding='utf-8'
sample=res.text
from bs4 import BeautifulSoup
soup=BeautifulSoup(sample,'html.parser')
header=soup.select('title')
print(header[0].text)

#h=soup.select('.news-item')
#for img in h:
#    print(img.text)

#爬虫新浪新闻网href
for news in soup.select('.news-item'):
    #所有的连接都在h2下面
    #print(news.select('h2'))
    if(len(news.select('h2'))>0):
        h2=news.select('h2')[0].text
        time=news.select('.time')[0].text
        a=news.select('a')[0]['href']
        print(time,h2,a)
